/*
 *
 *  * Copyright 2020 New Relic Corporation. All rights reserved.
 *  * SPDX-License-Identifier: Apache-2.0
 *
 */

package java.sql;

import com.newrelic.agent.bridge.datastore.DatastoreMetrics;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "java.sql.Statement", type = MatchType.Interface)
public abstract class Statement_Weaved {

    @Trace(leaf = true)
    public ResultSet executeQuery(String sql) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public int executeUpdate(String sql) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public boolean execute(String sql) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public int executeUpdate(String sql, String[] columnNames) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public boolean execute(String sql, String[] columnNames) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    @Trace(leaf = true)
    public boolean execute(String sql, int[] columnIndexes) throws SQLException {
        DatastoreMetrics.noticeSql(getConnection(), sql, null);
        return Weaver.callOriginal();
    }

    public abstract Connection getConnection() throws SQLException;

}
